package com.punch.user.controller;


import com.punch.common.dto.user.role.RoleMenuDTO;
import com.punch.common.model.Result;
import com.punch.common.page.PageInfo;
import com.punch.common.query.user.role.RoleQueryInfo;
import com.punch.common.vo.user.role.RoleVO;
import com.punch.user.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author 作者 owen E-mail: 624191343@qq.com
 * 角色管理
 */
@RestController
@Api(tags = "角色模块")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 后台管理查询角色
     *
     * @param queryInfo 查询条件
     * @return <PageInfo<SysRole>
     */
    @ApiOperation(value = "后台管理查询角色")
    @GetMapping(value = "/roles")
    public Result<PageInfo<RoleVO>> listRole(@ModelAttribute RoleQueryInfo queryInfo) {
        return Result.succeed(roleService.queryPage(queryInfo));
    }

    /**
     * 角色菜单功能权限
     *
     * @param roleMenuDTO 批量角色修改表单
     * @return Long
     * @author wujj
     * @since 2020/6/5 14:26
     */
    @PutMapping(value = "/role/menu-perm/batch", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "角色菜单功能权限", notes = "角色菜单功能权限", produces = "application/json; charset=utf-8")
    public Result<Long> roleMenuPerm(@Valid @RequestBody RoleMenuDTO roleMenuDTO) {
        return Result.succeed(roleService.roleMenuPerm(roleMenuDTO));
    }

    /**
     * 角色菜单功Id列表
     *
     * @param roleId 角色id
     * @return 菜单id
     * @author wujj
     * @since 2020/6/5 14:26
     */
    @GetMapping(value = "/role/menu/{roleId}", produces = "application/json; charset=utf-8")
    @ApiOperation(value = "角色菜单功Id列表", notes = "角色菜单功Id列表", produces = "application/json; charset=utf-8")
    public Result<List<String>> roleMenuList(@PathVariable Long roleId) {
        return Result.succeed(roleService.roleMenuList(roleId));
    }

}



